(ns pe.p52)

(defn -digits [x digs]
  (cond
    (< x 1) digs
    (< x 10) (-digits (/ x 10) (conj digs (int x)))
    :else (-digits (Math/floor (/ x 10)) (conj digs (rem (int x) 10)))))

(defn digits [x] (sort (-digits x [])))

(defn same-digits? [a b]
  (= (digits a) (digits b)))

(defn p42? [a]
  (every? #(same-digits? a (* % a)) (range 1 7)))

(println (first (drop-while #(not (p42? %)) (iterate inc 1))))